using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel;
using System.Collections.Generic;

namespace ERPBackend.Models
{
    public class PurchaseReceipt : BaseModel
    {
        [Required]
        [StringLength(50)]
        public string ReceiptCode { get; set; } = string.Empty;

        [Required]
        public int PurchaseOrderId { get; set; }

        [ForeignKey("PurchaseOrderId")]
        public PurchaseOrder? PurchaseOrder { get; set; }

        [Required]
        public int SupplierId { get; set; }

        [ForeignKey("SupplierId")]
        public Supplier? Supplier { get; set; }

        [Required]
        public DateOnly ReceiptDate { get; set; }

        [Required]
        public int WarehouseId { get; set; }

        [ForeignKey("WarehouseId")]
        public Warehouse? Warehouse { get; set; }

        [Required]
        [DefaultValue(0)]
        public byte Status { get; set; } = 0; // 0: 待审核, 1: 已审核, 2: 已驳回

        [Required]
        [Column(TypeName = "decimal(18, 4)")]
        public decimal TotalQuantity { get; set; } = 0;

        [Column(TypeName = "decimal(18, 4)")]
        public decimal QualifiedQuantity { get; set; } = 0;

        [Column(TypeName = "decimal(18, 4)")]
        public decimal UnqualifiedQuantity { get; set; } = 0;

        [StringLength(500)]
        public string? Remark { get; set; }

        public int? ApprovedBy { get; set; }

        public DateTime? ApprovedTime { get; set; }

        [StringLength(500)]
        public string? ApprovalComments { get; set; }

        // 导航属性
        public ICollection<PurchaseReceiptItem>? PurchaseReceiptItems { get; set; }
    }
}